/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Factura.java
 *
 * Created on 15/03/2012, 09:26:27 PM
 */

package veluanasoft.vista;

import java.util.ArrayList;
import java.util.Iterator;
import veluanasoft.control.InvoiceControl;
import veluanasoft.modelo.Invoice;
import veluanasoft.modelo.Item;

/**
 *
 * @author Ali Kate
 */
public class Factura extends javax.swing.JFrame {

    Invoice invoice;
    InvoiceControl invoiceControl;
    /** Creates new form Factura */
    public Factura(Invoice invoice, InvoiceControl invoiceControl) {
        initComponents();
        this.invoice = invoice;
        this.invoiceControl = invoiceControl;
        setSize(500, 400);
        jTextArea1.setEditable(false);
        cargarFactura();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(null);

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane1.setViewportView(jTextArea1);

        getContentPane().add(jScrollPane1);
        jScrollPane1.setBounds(10, 11, 470, 330);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    // End of variables declaration//GEN-END:variables

    private void cargarFactura() {
        ArrayList<Item> itemList = invoice.arrayItems();

        String texto = "VeLuana\n"
                + "NIT 800.000.000-X\n\n"
                + "Clliente: "+invoice.getBuyerName()+"\n"
                + "Dirección: "+invoice.getBuyerAddress()+"\n\n"
                + "Item\t\tQuatity\tPrice\tCost\n";
        
        for(Item item : itemList){
            texto += item.getWoodName()+"\t";
            texto += item.getQuantity()+"\t";
            texto += item.getPriceOfWood()+"\t";
            texto += item.getSubTotalPrice()+"\n";
        }
        texto += "\n";
        texto += "Precio Total: "+invoiceControl.totalPrice(invoice)+ "\n";
        texto += "Tiempo de entrega: "+invoiceControl.totalDeliveryTime(invoice)+" Horas\n";

        jTextArea1.setText(texto);
    }

}
